<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>   
 
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>/mobile/chat/chatChatting.jsp</title>
	
	<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"> 

	<LINK href="${cPath }/css/bud.css"  rel="stylesheet"  type="text/css"/>
	<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
	<SCRIPT type="text/javascript">
		$(document).on("mobileinit", function(){
			$.mobile.ajaxEnabled = false;
		});
		
		$(document).bind('pageinit', function(){
			location.hash = "aa";
		});
		
		var html = "";
		function insertChat(){
			if ($("#ch_chat").val() == ""){
				return;
			}
			$.post( 
				"${cPath }/chat/chatAdd.mo", 
				$("#chattingForm").serialize(), 
				function(data){
					html += "<div class='ui-grid-a'>";
					html += "<div class='ui-block-a' style='width:30%;'></div>";
					html += "<div class='ui-block-b' style='width:70%;'>";
					html += "<label for='basic' style='padding:5px; float:right; border-style:solid;border-width:thin;border-color:red;'>";
					html += document.chattingForm.ch_chat.value;
					html += "</label></div></div><br />";
					$("#ajaxHtml").html(html);
					document.chattingForm.ch_chat.value = "";
					location.hash = "aa";
				}
			);	
		}
		
	</SCRIPT>
	<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
	
</head>
<body>
<div id="chatChatting" data-role="page" data-theme="b">
	
	<div data-role="header" data-position="fixed" data-theme="a">
		<div style="left:5px; top:5px; z-index:10001;position:fixed;" >
			<img src="${cPath }/css/webbud.png" height="30px" />
		</div>
		<a href="${cPath }/logout.mo" id="back" data-icon="custom" class="ui-btn-right">로그아웃</a>
		<h1 >${friend.mem_name } 님과의 대화</h1>
		<div data-role="navbar" data-iconpos="top" >
			<ul>
				<li><a href="${cPath }/scan/scanMap.mo" id="scan" data-icon="custom" >Scan</a></li>
				<li><a href="${cPath }/bud/budList.mo" id="bud"  data-icon="custom" >Bud</a></li>
				<li><a href="${cPath }/chat/chatList.mo" id="chat" class="ui-btn-active" data-icon="custom">Chat</a></li>
				<li><a href="${cPath }/settings/setMain.mo" id="set" data-icon="custom">Settings</a></li>
			</ul>
		</div>
		
	</div>
		
	<div id="contentId" data-role="content">
		<c:set var="tempDate" value=""></c:set>
		<c:forEach var="chat" items="${chatList }">
			<c:if test="${tempDate != chat.ch_date1 }">
				<ul data-role="listview" data-divider-theme="d" style="padding: 5px; color: white;">
					<li style="text-align: center; background-color: pink;" data-role="list-divider" >${chat.ch_date1 }</li>
				</ul><br />
				<c:set var="tempDate" value="${chat.ch_date1 }"></c:set>
			</c:if>
			
			<c:if test="${chat.ch_sender == sessionScope.memberSession.mem_no }">
			<div class="ui-grid-a">
				<div class="ui-block-a" style="width:10%;">
				</div>
				<div class="ui-block-b" style="width:90%;">
					<label for="basic" style="padding:5px; max-width:75%; float:right; border-style:solid;border-width:thin;border-color:red;">${chat.ch_chat }</label>
					<label for="basic" style="width:20%; float:right;">${chat.ch_date2 }</label>
				</div>
			</div>
			</c:if>
			
			<c:if test="${chat.ch_sender != sessionScope.memberSession.mem_no }">
			<div class="ui-grid-a">
				<div class="ui-block-a" style="width: 18%; height: 12%;">
					<a href="${cPath }/bud/budProfile.mo?mem_no=${friend.mem_no}"><img src="data:image/jpeg;base64, ${friend.mem_photoStr }" width="50px" height="50px"/></a>
				</div>
				<div class="ui-block-b" style="width: 80%;">
					<label for="basic" style="padding:5px; max-width:70%; float:left; border-style:solid;border-width:thin;border-color:pink;">${chat.ch_chat }</label>
					<label for="basic" style="margin-left:5%; width:20%; float:left;">${chat.ch_date2 }</label>
				</div>
			</div>
			</c:if>
		<br />
		</c:forEach>
		<div id="ajaxHtml"></div>
		<a name="aa" />
		
	</div>
	
	<div id="footerId" data-role="footer" data-position="fixed" data-theme="a">		
		<FORM name="chattingForm" id="chattingForm" action="${cPath }/chat/chatAdd.mo" method="post" >
		<div class="ui-block-a" style="padding-left: 5%; width: 75%">
				<INPUT type="hidden" id="ch_receiver" name="ch_receiver" value="${param.mem_no }"/>
				<INPUT type="hidden" id="ch_sencer" name="ch_sender" value="${sessionScope.memberSession.mem_no }"/>
				<input type="text" id="ch_chat" name="ch_chat" value="" required="required"/>
		</div>
		<div class="ui-block-b" style="padding-top:3px; padding-right: 5%; float:right; width: 20%;" >
			<input type="button" value="전송"  onclick="insertChat();" data-theme="d"/>
		</div>
		</FORM>
	</div>
		
</div>

</body>
</html>